﻿#include "personinfoui.h"
#include "ui_personinfoui.h"
#include "opdb.h"
#include "login.h"
#include "personinfoedit.h"
#include "headui.h"


PersonInfoUI::PersonInfoUI(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PersonInfoUI)
{
    ui->setupUi(this);
    setWindowTitle(" ");
    setWindowFlags(Qt::FramelessWindowHint);//将窗口标题去掉
}


PersonInfoUI::~PersonInfoUI()
{
    delete ui;
}

void PersonInfoUI::mousePressEvent(QMouseEvent *event)
{
    isPressedWidget = true; // 当前鼠标按下的是QWidget而非界面上布局的其它控件
    last = event->globalPos();
}

void PersonInfoUI::mouseMoveEvent(QMouseEvent *event)
{
    if (isPressedWidget)
    {
        int dx = event->globalX() - last.x();
        int dy = event->globalY() - last.y();
        last = event->globalPos();
        move(x()+dx, y()+dy);
    }
}

void PersonInfoUI::mouseReleaseEvent(QMouseEvent *event)
{
    int dx = event->globalX() - last.x();
    int dy = event->globalY() - last.y();
    move(x()+dx, y()+dy);
    isPressedWidget = false; // 鼠标松开时，置为false
}

void PersonInfoUI::initUserInfo(QString name)
{
    //初始化个人信息
    QList<QString> list = OpDb::getInstance().getUserInfo(name);
    ui->label_ID_2->setText(list[0]);
    ui->label_address->setText(list[9]);
    ui->label_rubric->setText(list[11]);
    ui->textBrowser->setText(list[5]);
    QString str = QString("min-width:  80px;max-width:  80px;min-height: 80px;max-height: 80px;border-radius: 40px;border-width: 1 1 1 1;border-image: url(%1) 0 0 0 0 stretch strectch;").arg(list[4]);
    ui->label_head->setStyleSheet(str);
    ui->label_14->setText(list[1]);
    QString str2 = list[2]+"   "+list[3]+"   "+list[7]+"   "+list[8]+"   "+list[12];
    ui->label_Info_2->setText(str2);
    ui->label_phone->setText(list[10]);
    ui->label_2->setText(list[6]);

}

void PersonInfoUI::hideEditInofoBtn()
{
    ui->btn_editinfo->hide();
}

void PersonInfoUI::on_btn_close_clicked()
{
    close();
    destroy();
}

void PersonInfoUI::on_btn_min_clicked()
{
    showMinimized();
}

void PersonInfoUI::on_btn_editinfo_clicked()
{
    PersonInfoEdit* pedit = new PersonInfoEdit;
    pedit->show();
}

void PersonInfoUI::on_label_head_clicked()//更换头像
{
    QDir dir("D:\\QTCode5.14\\CClient\\res");
    QStringList list = dir.entryList(QDir::Files);
    HeadUI* headui = new HeadUI;
    for(auto x:list)
    {
        if(x.contains(".jpg")||x.contains(".png"))
        {
            QString temp = "D:\\QTCode5.14\\CClient\\res\\"+x;
            headui->init(temp);
        }
    }
    headui->show();
}
